﻿@{
	Layout = null;
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>职称设置</title>
	<link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
</head>
<body>
	<script src="https://unpkg.com/vue@3"></script>
	<!-- 引入Element Plus -->
	<script src="https://unpkg.com/element-plus"></script>
	<!-- 引入axios -->
	<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
	<div id="app">
		<el-form :model="formData" ref="formData" label-width="110px" class="demo-ruleForm">
			<table width="100%">
				<tr>
					<td>
						<font color="black">您正在做的业务是：人力资源--权限管理--编辑角色</font>
					</td>
				</tr>
				<tr>
					<td align="right">
						<el-button style="float:right" v-on:click="Add()">保存</el-button>
						<el-button style="float:right" onclick="history.back()">返回</el-button>
					</td>
				</tr>
			</table>
			<table width="100%" border="1" cellpadding=3 cellspacing=1 class="TABLE_STYLE1">
				<tr>
					<td class="TD_STYLE1">角色编号</td>
					<td class="TD_STYLE2">
						<el-form-item prop="RolesID">
							<el-input v-model="uid"></el-input>
						</el-form-item>
					</td>
					<td class="TD_STYLE1">角色名称</td>
					<td class="TD_STYLE2">
						<el-form-item prop="RolesName">
							<el-input v-model="formData.RolesName"></el-input>
						</el-form-item>
					</td>
				</tr>
				<tr>
					<td class="TD_STYLE1">角色说明</td>
					<td class="TD_STYLE2">
						<el-form-item prop="RolesInstruction">
							<el-input v-model="formData.RolesInstruction"></el-input>
						</el-form-item>
					</td>
					<td class="TD_STYLE1">角色是否可用</td>
					<td class="TD_STYLE2">
						<el-form-item prop="Uidentity">
							<el-select v-model="selected" placeholder="请选择">
								<el-option label="是" value="1"></el-option>
								<el-option label="否" value="0"></el-option>
							</el-select>
						</el-form-item>
					</td>
				</tr>
			</table>
			@* :default-checked-keys.sync="defualtkeys" *@
		</el-form>
		<div style="margin-top:50px">
			<el-tree :data="data"
					 default-expand-all
					 accordion
					 ref="rolesJurisdiction"
					 show-checkbox
					 node-key="juriID"
					 :default-checked-keys.sync="defualtkeys"
					 :props="defaultProps"
					 v-on:check="getid">
			</el-tree>

		</div>
	</div>

	<script>
		const app = Vue.createApp({
			data() {
				return {

					rolesJurisdiction: [],
					drawer: false,
					direction: 'rtl',
					tableData: [],
					data: [],
					defaultProps: {
						label: "jurName",
						children: "children"
					},
					defualtkeys: [],

					uid: JSON.parse(sessionStorage.getItem('uId5') || '[]'),
					formData: {
						RolesID:'',//角色编号
						RolesName:'',//角色名称
						RolesInstruction:'',//角色说明
					},
					selected: 1,
					
					attributeName: '',
					pbcId: 0,
				};
			},
			methods: {
				Add() {
				
					axios.get("/User/UpdateRole?RolesName=" + this.formData.RolesName + "&RolesInstruction=" + this.formData.RolesInstruction + "&RolesIf=" + this.selected + "&JuriID=" + this.rolesJurisdiction + "&RolesID=" + this.uid)
						.then(function (response) {
							if (response.data) {
								alert("成功！");
							} else {
								alert("添加失败！！");
							}
						})
						.catch(function (error) {
							console.error(error);
							alert("请求失败");
						});
				},
				show() {
					var dq = this;
					axios.get("/User/Shwo?id="+this.uid)
						.then(function (res) {
							console.log(res.data[0]);
							dq.formData.RolesName = res.data[0].rolesName;
							dq.formData.RolesInstruction = res.data[0].rolesInstruction;
							if (res.data[0].rolesIf == 1) {
								dq.selected = 1;
							}
						})
						.catch(function (error) {
							console.error(error);
						});
				},
				Updates() {
					axios.get('/User/trees2')
						.then(res => {
						
							this.data = res.data
							
						})
						.catch(err => {
							console.log(err);
						})
				},
				//查询指定角色权限
				Updatesid() {
					axios.get('/User/selectRolesJurisdiction?id='+this.uid)
					    .then(res => {
							this.defualtkeys = res.data;
							this.rolesJurisdiction = res.data;
					    })
					    .catch(err => {
					        console.log(err);
					    })
				},
				//查看节点选中
				getid() {
					this.rolesJurisdiction = this.$refs.rolesJurisdiction.getCheckedKeys()
					
				},
				RJInserts() {
					// axios.get(`/usermanagement/deleteRolesJurisdiction?id=${this.uid}`)
					//     .then(res => {

					//             alert("删除成功")

					//         for (var i in this.rolesJurisdiction) {
					//             //alert(this.rolesJurisdiction);
					//             axios.post('/usermanagement/insertRolesJurisdiction', {
					//                 RolesID: this.uid,
					//                 JuriID: this.rolesJurisdiction[i]
					//             })
					//                 .then(res => {

					//                         console.log("增加成功");

					//                 })
					//                 .catch(err => {
					//                     console.log(err);
					//                 })
					//         }
					//     })
					//     .catch(err => {
					//         console.log(err);
					//     })
				},
			},
			mounted() {
				this.show();
				this.Updates();
				this.Updatesid();
				
			}
		});

		// 安装 Element Plus
		app.use(ElementPlus);

		// 挂载应用程序到页面上
		app.mount("#app");
	</script>
</body>
</html>

